import service from './index';

// 获取首页数据
export const getHomePageData = (params: { pageNum?: number; pageSize?: number; tagIdList?: number[] }) => {
    // 将数组转换为逗号分隔的字符串，避免 tagIdList[] 格式
    const processedParams: any = { ...params };
    if (Array.isArray(params.tagIdList)) {
        processedParams.tagIdList = params.tagIdList.join(',');
    }
    return service.get('/article/homePage', { params: processedParams });
};

// 获取所有分类
export const getAllCategory = () => {
    return service.get('/article/allCategory');
};

// 获取文章分页数据
export const getArticlePage = (params: { categoryId?: string | null; pageNum?: number; pageSize?: number; search?: string | null; tagIdList?: number[] }) => {
    const processedParams: any = { ...params };
    if (Array.isArray(params.tagIdList)) {
        processedParams.tagIdList = params.tagIdList.join(',');
    }
    return service.get('/article/page', { params: processedParams });
};

// 获取文章详情
export const getArticleDetail = (params: { id?: string | null }) => {
    return service.get('/article/detail', { params });
};

// 根据关键词获取文章分页数据（原 POST 改为 GET）
export const getArticlePageByKeyword = (params: { pageNum?: number; pageSize?: number; keyword?: string }) => {
    return service.get('/article/pageByKeyword', { params });
};

// 转发 API（使用 POST）
export const forwardApi = (data: { hit?: string; keyword?: string; title?: string | number; articleId?: string | number; siteName?: string }) => {
    return service.post('/forward/api', data);
};

